package com.thinqq.web.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.thinqq.web.client.content.handler.LinkClickHandler;
import com.thinqq.web.client.content.handler.SearchBoxHandler;
import com.thinqq.web.client.content.painter.CommunicationContentPainter;
import com.thinqq.web.client.content.painter.ContentPainterRegistry;
import com.thinqq.web.client.content.painter.EnquireThinqqContentPainer;
import com.thinqq.web.client.content.painter.IContentPainter;
import com.thinqq.web.client.content.painter.InformationTechnologyContentPainter;
import com.thinqq.web.client.content.painter.MainMenuCommand;
import com.thinqq.web.client.content.painter.ProductDevelopmentContentPainter;
import com.thinqq.web.client.content.painter.ThinqQHomeContentPainter;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Thinqqw implements EntryPoint {

	HorizontalPanel header = new HorizontalPanel();
	HorizontalPanel content = new HorizontalPanel();
	HorizontalPanel footer = new HorizontalPanel();
	HorizontalPanel mainContent = new HorizontalPanel();
	VerticalPanel sidebarContent = new VerticalPanel();
	VerticalPanel relatedContent = new VerticalPanel();
	ScrollPanel scrollPanel = new ScrollPanel();
	ThinqQImageBundle bundle = GWT.create(ThinqQImageBundle.class);
	  //ContentServiceAsync contentService = GWT.create(ContentService.class);
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		String showcontent = Window.Location.getParameter("content"); 
		IContentPainter bookmarkContentPainter = ContentPainterRegistry.getContentPainter(showcontent);
		
		header.setStyleName("header");
		Image logo = new Image(bundle.getLogo());
		header.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		header.add(logo);
		MenuBar menu = buildMenuBar();
		header.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
		header.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		header.add(menu);
		Grid searchInquireGrid = new Grid(2,1);
		//Search Box code- Start
		HorizontalPanel searchPanel = new HorizontalPanel();
		searchPanel.setStyleName("searchpanel");
		searchPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		searchPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();  
		buildSearchOprions(oracle);
		SuggestBox searchBox = new SuggestBox(oracle);
		searchBox.addKeyPressHandler(new SearchBoxHandler(searchBox));
		searchBox.setStyleName("marginbottom3");
		PushButton searchThinqQ = new PushButton("Search");
		searchThinqQ.setPixelSize(80, 31);
		searchThinqQ.addClickHandler(new SearchBoxHandler(searchBox));
		searchThinqQ.setStyleName("searchlink");
		searchPanel.add(searchBox);
		searchPanel.add(searchThinqQ);
		searchInquireGrid.setWidget(0,0,searchPanel);
		header.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		header.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		header.add(searchInquireGrid);
		//Enquire ThinqQ Services link - end
		RootPanel headerRoot = RootPanel.get("header");
		//head.add();
		headerRoot.add(header);
		/*Content code - Start*/
		content.setStyleName("content");
		content.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
		content.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
		content.add(mainContent);
		mainContent.setStyleName("maincontent");
		mainContent.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
		RootPanel contentRoot = RootPanel.get("content");
		contentRoot.add(content);
		buildFooter();
		RootPanel footerRoot = RootPanel.get("footer");
		footerRoot.add(footer);
		IContentPainter contentPainter;
		if(bookmarkContentPainter!=null){
			contentPainter= bookmarkContentPainter;
		}else{
			contentPainter = ContentPainterRegistry.getContentPainter(ContentPainterRegistry.HOME);
		}
		contentPainter.updateConent(mainContent, relatedContent);
	}
	private void buildSearchOprions(MultiWordSuggestOracle oracle) {
		oracle.add("Information Technology");
		   oracle.add("Technology");
		   oracle.add("Product development");
		   oracle.add("Maintainence");
		
	}
	private MenuBar buildMenuBar() {
		MenuBar  servicesMenu = new MenuBar(true);
		servicesMenu.addItem("Information technology", menuCmdITS);
		servicesMenu.addItem("Product development", menuCmdProdDev);
		//servicesMenu.addItem("Comprehensive Business solutions", menuCmdITS);
		//servicesMenu.addItem("Organisation Management solutions", menuCmdITS);
		 /*MenuBar industriesMenu = new MenuBar(true);
		 industriesMenu.addItem("Communication", menuCmdCommunication);
		 industriesMenu.addItem("Technology", menuCmdITS);
		 industriesMenu.addItem("Energy and Utilities", menuCmdITS);
		 industriesMenu.addItem("Retail", menuCmdITS);
		 industriesMenu.addItem("Transportation and Logistics", menuCmdITS);*/
		 MenuBar thinqqMenu = new MenuBar(true);
		 thinqqMenu.addItem("ThinqQ Blog", menuCmdITS);
		 thinqqMenu.addItem("ThinqQ Network", menuCmdITS);
		 thinqqMenu.addItem("ThinqQ Cartoons", menuCmdITS);


		    // Make a new menu bar, adding a few cascading menus to it.
		    MenuBar menu = new MenuBar();
		    menu.addSeparator();
		    MenuItem home =menu.addItem("Home",true,menuCmdHome );
		    home.setStyleName("enquiremenuitem");
		    menu.addSeparator();
		    MenuItem servicesItem =menu.addItem("Services",true, servicesMenu);
		    servicesItem.setStyleName("menuitem");
		    menu.addSeparator();
		    /*MenuItem industriesItem = menu.addItem("Industries",true, industriesMenu);
		    industriesItem.setStyleName("menuitem");
		    menu.addSeparator();*/
		    MenuItem thinqQItem =menu.addItem("ThinqQ",true, thinqqMenu);
		    thinqQItem.setStyleName("menuitem");
		    menu.addSeparator();
		    MenuItem enquireThinqq =menu.addItem("Enquire ThinqQ",true,menuCmdEnquire);
		    enquireThinqq.setStyleName("enquiremenuitem");


		    
		    menu.setAnimationEnabled(true);
		    menu.setAutoOpen(true);
		    menu.setStyleName("menubar");
		    return menu;
	}
	
	private void  buildFooter(){
		footer.setStyleName("footer");
		Anchor sitemap = new Anchor("Site Map");
		sitemap.addClickHandler(new LinkClickHandler(ContentPainterRegistry.getContentPainter(ContentPainterRegistry.SITE_MAP), mainContent, relatedContent));
		sitemap.addStyleName("footer_anchor");
		Anchor privacyPolicy = new Anchor("Privacy Policy");
		privacyPolicy.addStyleName("footer_anchor");
		Anchor contactThinqQ = new Anchor("Contact ThinqQ");
		contactThinqQ.addStyleName("footer_anchor");
		Label copyright = new Label("Copyright 2011 ThinqQ");
		copyright.setStyleName("greytext");
		Grid footerGrid = new Grid(1,3);
		footer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
		footerGrid.setWidget(0,0,sitemap);
		footerGrid.setWidget(0,1,privacyPolicy);
		footerGrid.setWidget(0,2,contactThinqQ);
		footer.add(footerGrid);
		footer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		footer.add(copyright);
		
		
	}
      Command menuCmdCommunication = new MainMenuCommand(new CommunicationContentPainter(),mainContent,relatedContent) {};
      Command menuCmdITS = new MainMenuCommand(new InformationTechnologyContentPainter(),mainContent,relatedContent) {};
      Command menuCmdEnquire = new MainMenuCommand(new EnquireThinqqContentPainer(),mainContent,relatedContent) {};
      Command menuCmdHome = new MainMenuCommand(new ThinqQHomeContentPainter(),mainContent,relatedContent) {};
      Command menuCmdProdDev = new MainMenuCommand(new ProductDevelopmentContentPainter(),mainContent,relatedContent) {};
      
}
